package tabdulin.sms.megafon;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.swing.text.html.HTMLEditorKit.ParserCallback;
import javax.swing.text.html.parser.ParserDelegator;

/**
 * @author Talgat Abdulin
 *
 */
public class MegafonStatus {
    private String link = null;
    
    public MegafonStatus(InputStream inputStream) throws IOException {
        InputStreamReader response = new InputStreamReader(inputStream);
        ParserDelegator parser = new ParserDelegator();
        ParserCallback parserCallback = new MegafonStatusSeeeker();
        parser.parse(response, parserCallback, false);
        this.link = ((MegafonStatusSeeeker) parserCallback).getStatusLink();
        response.close();
    }

    public String getLink() {
        return link;
    }

    public String getMessage() {
        if (link != null && link.startsWith("/send/status/")) {
            return"Message was sent.";
        } 
        return"Message was NOT sent, write new one.";
    }
}
